﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Mod_PopedomManage_frm_RolesAllot : System.Web.UI.Page
{
    public void SelectedIndexChanged(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        ListBox lstBox = (ListBox)sender;

        int intMenuID = Int32.Parse(lstBox.SelectedItem.Value);
        this.hidMenuID.Value = intMenuID.ToString();
        DataSet dst = cls_Menu.GetSysButtonsByMenu(intMenuID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.dgrd0.DataSource = dst;
            this.dgrd0.DataBind();

            int intUserID = Int32.Parse(this.hidUserID.Value.Trim());
            dst = cls_Menu.GetSysButtonsByUMID(intUserID, intMenuID);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                this.chkPriceVisible.Visible = true;

                int intButton0 = this.dgrd0.Items.Count - 1;
                int intButton1 = dst.Tables[0].Rows.Count - 1;

                for (int i = intButton0; i >= 0; i--)
                {
                    for (int j = intButton1; j >= 0; j--)
                    {
                        if (this.dgrd0.Items[i].Cells[1].Text.ToString() == dst.Tables[0].Rows[j][0].ToString())
                        {
                            ((CheckBox)this.dgrd0.Items[i].FindControl("chkRsSelect")).Checked = true;

                            break;
                        }
                    }
                }
            }
        }
        else
        {
            this.chkPriceVisible.Visible = false;
            this.dgrd0.DataSource = null;
            this.dgrd0.DataBind();
        }

    }

    public void MenuMove(object sender, EventArgs e)
    {
        int intCommand = Int32.Parse(((Button)sender).CommandName);

        if (intCommand == 0)//添加
        {
            if (this.lstBox1.SelectedIndex != -1)
            {
                int i = 0;

                while ( i < this.lstBox1.Items.Count)
                {
                    if (this.lstBox1.Items[i].Selected)
                    {
                        this.lstBox2.Items.Insert(0, this.lstBox1.Items[i]);
                        this.lstBox1.Items.Remove(this.lstBox1.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要添加的菜单项！');</script>";
            }
        }
        else//移废
        {
            if (this.lstBox2.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstBox2.Items.Count)
                {
                    if (this.lstBox2.Items[i].Selected)
                    {
                        this.lstBox1.Items.Insert(0, this.lstBox2.Items[i]);
                        this.lstBox2.Items.Remove(this.lstBox2.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要作废的菜单项！');</script>";
            }
        }

        this.lblMenu1.Text = "(" + this.lstBox1.Items.Count + "项)";
        this.lblMenu2.Text = "(" + this.lstBox2.Items.Count + "项)";
    }

    public void DeptMove(object sender, EventArgs e)
    {
        int intCommand = Int32.Parse(((Button)sender).CommandName);

        if (intCommand == 0)//添加
        {
            if (this.lstDept1.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstDept1.Items.Count)
                {
                    if (this.lstDept1.Items[i].Selected)
                    {
                        this.lstDept2.Items.Insert(0, this.lstDept1.Items[i]);
                        this.lstDept1.Items.Remove(this.lstDept1.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要添加的部门项！');</script>";
            }
        }
        else//移废
        {
            if (this.lstDept2.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstDept2.Items.Count)
                {
                    if (this.lstDept2.Items[i].Selected)
                    {
                        this.lstDept1.Items.Insert(0, this.lstDept2.Items[i]);
                        this.lstDept2.Items.Remove(this.lstDept2.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要作废的部门项！');</script>";
            }
        }

        this.lblDept1.Text = "(" + this.lstDept1.Items.Count + "项)";
        this.lblDept2.Text = "(" + this.lstDept2.Items.Count + "项)";
    }

    public void DepotMove(object sender, EventArgs e)
    {
        int intCommand = Int32.Parse(((Button)sender).CommandName);

        if (intCommand == 0)//添加
        {
            if (this.lstDepot1.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstDepot1.Items.Count)
                {
                    if (this.lstDepot1.Items[i].Selected)
                    {
                        this.lstDepot2.Items.Insert(0, this.lstDepot1.Items[i]);
                        this.lstDepot1.Items.Remove(this.lstDepot1.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要添加的仓库项！');</script>";
            }
        }
        else//移废
        {
            if (this.lstDepot2.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstDepot2.Items.Count)
                {
                    if (this.lstDepot2.Items[i].Selected)
                    {
                        this.lstDepot1.Items.Insert(0, this.lstDepot2.Items[i]);
                        this.lstDepot2.Items.Remove(this.lstDepot2.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要作废的仓库项！');</script>";
            }
        }

        this.lblDepot1.Text = "(" + this.lstDepot1.Items.Count + "项)";
        this.lblDepot2.Text = "(" + this.lstDepot2.Items.Count + "项)";
    }

    public void ProductTypeMove(object sender, EventArgs e)
    {
        int intCommand = Int32.Parse(((Button)sender).CommandName);

        if (intCommand == 0)//添加
        {
            if (this.lstProductType1.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstProductType1.Items.Count)
                {
                    if (this.lstProductType1.Items[i].Selected)
                    {
                        this.lstProductType2.Items.Insert(0, this.lstProductType1.Items[i]);
                        this.lstProductType1.Items.Remove(this.lstProductType1.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要添加的商品类别！');</script>";
            }
        }
        else//移废
        {
            if (this.lstProductType2.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstProductType2.Items.Count)
                {
                    if (this.lstProductType2.Items[i].Selected)
                    {
                        this.lstProductType1.Items.Insert(0, this.lstProductType2.Items[i]);
                        this.lstProductType2.Items.Remove(this.lstProductType2.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要作废的商品类别！');</script>";
            }
        }

        this.lblProductType1.Text = "(" + this.lstProductType1.Items.Count + "项)";
        this.lblProductType2.Text = "(" + this.lstProductType2.Items.Count + "项)";
    }

    public void OderTypeMove(object sender, EventArgs e)
    {
        int intCommand = Int32.Parse(((Button)sender).CommandName);

        if (intCommand == 0)//添加
        {
            if (this.lstOderType1.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstOderType1.Items.Count)
                {
                    if (this.lstOderType1.Items[i].Selected)
                    {
                        this.lstOderType2.Items.Insert(0, this.lstOderType1.Items[i]);
                        this.lstOderType1.Items.Remove(this.lstOderType1.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要添加的客户类别！');</script>";
            }
        }
        else//移废
        {
            if (this.lstOderType2.SelectedIndex != -1)
            {
                int i = 0;

                while (i < this.lstOderType2.Items.Count)
                {
                    if (this.lstOderType2.Items[i].Selected)
                    {
                        this.lstOderType1.Items.Insert(0, this.lstOderType2.Items[i]);
                        this.lstOderType2.Items.Remove(this.lstOderType2.Items[i]);
                        i = 0;
                    }
                    else
                    {
                        i++;
                    }
                }
            }
            else
            {
                this.lblJs.Text = "<script>alert('请选择要作废的客户类别！');</script>";
            }
        }

        this.lblOderType1.Text = "(" + this.lstOderType1.Items.Count + "项)";
        this.lblOderType2.Text = "(" + this.lstOderType2.Items.Count + "项)";
    }

    private void BindMenuByMenuRolseDataSet(string CurrUserID, int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst0 = cls_Menu.GetSysMenuItemsByCurrUserID(CurrUserID);
        DataSet dst1 = cls_Menu.GetSysMenuItemsByUserID(UserID);

        if (dst0 != null && dst0.Tables[0].Rows.Count > 0)
        {
            this.lstBox1.Items.Clear();
            this.lstBox1.DataTextField = "m_item_name";
            this.lstBox1.DataValueField = "m_item_id";
            this.lstBox1.DataSource = dst0;
            this.lstBox1.DataBind();

            if (dst1 != null && dst1.Tables[0].Rows.Count > 0)
            {
                this.lstBox2.Items.Clear();
                this.lstBox2.DataTextField = "m_item_name";
                this.lstBox2.DataValueField = "m_item_id";
                this.lstBox2.DataSource = dst1;
                this.lstBox2.DataBind();

                for (int i = this.lstBox2.Items.Count - 1; i >= 0; i--)
                {
                    for (int j = this.lstBox1.Items.Count - 1; j >= 0; j--)
                    {
                        if (this.lstBox2.Items[i].Text.Trim() == this.lstBox1.Items[j].Text.Trim())
                        {
                            this.lstBox1.Items.Remove(this.lstBox1.Items[j]);
                            break;
                        }
                    }
                }
            }

            this.lblMenu1.Text = "(" + this.lstBox1.Items.Count + "项)";
            this.lblMenu2.Text = "(" + this.lstBox2.Items.Count + "项)";
            if (this.lstBox1.Items.Count > 0) this.lstBox1.Items[0].Selected = true;
        }
        else
        {
            this.lblJs.Text = "<script>alert('获取系统菜单项失败，请关闭后重试！');window.close();</script>";
        }
    }

    private void BindMenuByButtonRolseDataSet(int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetSysMenuItemsByUserID(UserID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            this.lstBox3.Items.Clear();
            this.lstBox3.DataTextField = "m_item_name";
            this.lstBox3.DataValueField = "m_item_id";
            this.lstBox3.DataSource = dst;
            this.lstBox3.DataBind();
        }
    }

    private void BindDeptByDeptRolseDataSet(string CurrUserID, int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst0 = cls_Menu.GetDeptsByCurrUserID(CurrUserID);
        DataSet dst1 = cls_Menu.GetDeptsByUserID(UserID);

        if (dst0 != null && dst0.Tables[0].Rows.Count > 0)
        {
            this.lstDept1.Items.Clear();
            this.lstDept1.DataTextField = "dp_name";
            this.lstDept1.DataValueField = "dp_id";
            this.lstDept1.DataSource = dst0;
            this.lstDept1.DataBind();

            if (dst1 != null && dst1.Tables[0].Rows.Count > 0)
            {
                this.lstDept2.Items.Clear();
                this.lstDept2.DataTextField = "dp_name";
                this.lstDept2.DataValueField = "dp_id";
                this.lstDept2.DataSource = dst1;
                this.lstDept2.DataBind();

                for (int i = this.lstDept2.Items.Count - 1; i >= 0; i--)
                {
                    for (int j = this.lstDept1.Items.Count - 1; j >= 0; j--)
                    {
                        if (this.lstDept2.Items[i].Text.Trim() == this.lstDept1.Items[j].Text.Trim())
                        {
                            this.lstDept1.Items.Remove(this.lstDept1.Items[j]);
                            break;
                        }
                    }
                }
            }

            this.lblDept1.Text = "(" + this.lstDept1.Items.Count + "项)";
            this.lblDept2.Text = "(" + this.lstDept2.Items.Count + "项)";
            if (this.lstDept1.Items.Count > 0) this.lstDept1.Items[0].Selected = true;
        }
        else
        {
            this.lblJs.Text = "<script>alert('您当前无权对部门进行授权！');window.close();</script>";
        }
    }

    private void BindDepotByDepotRolseDataSet(string CurrUserID, int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst0 = cls_Menu.GetDepotsByCurrUserID(CurrUserID);
        DataSet dst1 = cls_Menu.GetDepotsByUserID(UserID);

        if (dst0 != null && dst0.Tables[0].Rows.Count > 0)
        {
            this.lstDepot1.Items.Clear();
            this.lstDepot1.DataTextField = "wh_name";
            this.lstDepot1.DataValueField = "wh_id";
            this.lstDepot1.DataSource = dst0;
            this.lstDepot1.DataBind();

            if (dst1 != null && dst1.Tables[0].Rows.Count > 0)
            {
                this.lstDepot2.Items.Clear();
                this.lstDepot2.DataTextField = "wh_name";
                this.lstDepot2.DataValueField = "wh_id";
                this.lstDepot2.DataSource = dst1;
                this.lstDepot2.DataBind();

                for (int i = this.lstDepot2.Items.Count - 1; i >= 0; i--)
                {
                    for (int j = this.lstDepot1.Items.Count - 1; j >= 0; j--)
                    {
                        if (this.lstDepot2.Items[i].Text.Trim() == this.lstDepot1.Items[j].Text.Trim())
                        {
                            this.lstDepot1.Items.Remove(this.lstDepot1.Items[j]);
                            break;
                        }
                    }
                }
            }

            this.lblDepot1.Text = "(" + this.lstDepot1.Items.Count + "项)";
            this.lblDepot2.Text = "(" + this.lstDepot2.Items.Count + "项)";
            if (this.lstDepot1.Items.Count > 0) this.lstDepot1.Items[0].Selected = true;
        }
        else
        {
            this.lblJs.Text = "<script>alert('您当前无权对仓库进行授权！');window.close();</script>";
        }
    }

    private void BindProductTypeByProductTypeRolseDataSet(string CurrUserID, int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst0 = cls_Menu.GetProductTypesByCurrUserID(CurrUserID);
        DataSet dst1 = cls_Menu.GetProductTypesByUserID(UserID);

        if (dst0 != null && dst0.Tables[0].Rows.Count > 0)
        {
            this.lstProductType1.Items.Clear();
            this.lstProductType1.DataTextField = "it_name";
            this.lstProductType1.DataValueField = "it_id";
            this.lstProductType1.DataSource = dst0;
            this.lstProductType1.DataBind();

            if (dst1 != null && dst1.Tables[0].Rows.Count > 0)
            {
                this.lstProductType2.Items.Clear();
                this.lstProductType2.DataTextField = "it_name";
                this.lstProductType2.DataValueField = "it_id";
                this.lstProductType2.DataSource = dst1;
                this.lstProductType2.DataBind();

                for (int i = this.lstProductType2.Items.Count - 1; i >= 0; i--)
                {
                    for (int j = this.lstProductType1.Items.Count - 1; j >= 0; j--)
                    {
                        if (this.lstProductType2.Items[i].Text.Trim() == this.lstProductType1.Items[j].Text.Trim())
                        {
                            this.lstProductType1.Items.Remove(this.lstProductType1.Items[j]);
                            break;
                        }
                    }
                }
            }

            this.lblProductType1.Text = "(" + this.lstProductType1.Items.Count + "项)";
            this.lblProductType2.Text = "(" + this.lstProductType2.Items.Count + "项)";
            if (this.lstProductType1.Items.Count > 0) this.lstProductType1.Items[0].Selected = true;
        }
        else
        {
            this.lblJs.Text = "<script>alert('您当前无权对商品类别进行授权！');window.close();</script>";
        }
    }

    private void BindPriceByPriceRolseDataSet(int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst = cls_Menu.GetPriceByUserID(UserID);

        if (dst != null && dst.Tables[0].Rows.Count > 0)
        {
            bool bol1 = bool.Parse(dst.Tables[0].Rows[0][1].ToString());
            bool bol2 = bool.Parse(dst.Tables[0].Rows[0][2].ToString());
            string pic1 = dst.Tables[0].Rows[0][3].ToString();
            string pic2 = dst.Tables[0].Rows[0][4].ToString();
            string pic3 = dst.Tables[0].Rows[0][5].ToString();
            string pic4 = dst.Tables[0].Rows[0][6].ToString();

            this.chkBox1.Checked = bol1;
            this.chkBox2.Checked = bol2;
            this.txt1.Enabled = this.txt2.Enabled = bol1;
            this.txt3.Enabled = this.txt4.Enabled = bol2;
            this.txt1.Text = pic1;
            this.txt2.Text = pic2;
            this.txt3.Text = pic3;
            this.txt4.Text = pic4;
        }
    }

    private void BindOderTypeByOderTypeRolseDataSet(string CurrUserID, int UserID)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        DataSet dst0 = cls_Menu.GetOderTypesByCurrUserID(CurrUserID);
        DataSet dst1 = cls_Menu.GetOderTypesByUserID(UserID);

        if (dst0 != null && dst0.Tables[0].Rows.Count > 0)
        {
            this.lstOderType1.Items.Clear();
            this.lstOderType1.DataTextField = "ik_name";
            this.lstOderType1.DataValueField = "ik_id";
            this.lstOderType1.DataSource = dst0;
            this.lstOderType1.DataBind();

            if (dst1 != null && dst1.Tables[0].Rows.Count > 0)
            {
                this.lstOderType2.Items.Clear();
                this.lstOderType2.DataTextField = "ik_name";
                this.lstOderType2.DataValueField = "ik_id";
                this.lstOderType2.DataSource = dst1;
                this.lstOderType2.DataBind();

                for (int i = this.lstOderType2.Items.Count - 1; i >= 0; i--)
                {
                    for (int j = this.lstOderType1.Items.Count - 1; j >= 0; j--)
                    {
                        if (this.lstOderType2.Items[i].Text.Trim() == this.lstOderType1.Items[j].Text.Trim())
                        {
                            this.lstOderType1.Items.Remove(this.lstOderType1.Items[j]);
                            break;
                        }
                    }
                }
            }

            this.lblOderType1.Text = "(" + this.lstOderType1.Items.Count + "项)";
            this.lblOderType2.Text = "(" + this.lstOderType2.Items.Count + "项)";
            if (this.lstOderType1.Items.Count > 0) this.lstOderType1.Items[0].Selected = true;
        }
        else
        {
            this.lblJs.Text = "<script>alert('您当前无权对客户类别进行授权！');window.close();</script>";
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();

            string strUserID = cls_Property.SetOrGetUserID;

            if (strUserID != "")
            {
                string strTitle = "";
                int intUserID = Int32.Parse(this.Page.Request.Params["UserID"].ToString());// 所选用户ID
                int intPopedomType = Int32.Parse(this.Page.Request.Params["PopedomType"].ToString());//权限类别
                this.hidUserID.Value = intUserID.ToString();

                switch (intPopedomType)
                {
                    case 0:
                        strTitle = "菜单权限";
                        this.BindMenuByMenuRolseDataSet(strUserID, intUserID);
                        this.pan0.Visible = true;
                        this.pan1.Visible = this.pan2.Visible = this.pan3.Visible = this.pan4.Visible = this.pan5.Visible = this.pan6.Visible = false;
                        break;
                    case 1:
                        strTitle = "按钮权限";
                        this.BindMenuByButtonRolseDataSet(intUserID);
                        this.pan1.Visible = true;
                        this.pan0.Visible = this.pan2.Visible = this.pan3.Visible = this.pan4.Visible = this.pan5.Visible = this.pan6.Visible = false;
                        break;
                    case 2:
                        strTitle = "部门权限";
                        this.BindDeptByDeptRolseDataSet(strUserID, intUserID);
                        this.pan2.Visible = true;
                        this.pan0.Visible = this.pan1.Visible = this.pan3.Visible = this.pan4.Visible = this.pan5.Visible = this.pan6.Visible = false;
                        break;
                    case 3:
                        strTitle = "仓库权限";
                        this.BindDepotByDepotRolseDataSet(strUserID, intUserID);
                        this.pan3.Visible = true;
                        this.pan0.Visible = this.pan1.Visible = this.pan2.Visible = this.pan4.Visible = this.pan5.Visible = this.pan6.Visible = false;
                        break;
                    case 4:
                        strTitle = "商品权限";
                        this.BindProductTypeByProductTypeRolseDataSet(strUserID, intUserID);
                        this.pan4.Visible = true;
                        this.pan0.Visible = this.pan1.Visible = this.pan2.Visible = this.pan3.Visible = this.pan5.Visible = this.pan6.Visible = false;
                        break;
                    case 5:
                        strTitle = "价格权限";
                        this.BindPriceByPriceRolseDataSet(intUserID);
                        this.pan5.Visible = true;
                        this.pan0.Visible = this.pan1.Visible = this.pan2.Visible = this.pan3.Visible = this.pan4.Visible = this.pan6.Visible = false;
                        break;
                    default:
                        strTitle = "客户权限";
                        this.BindOderTypeByOderTypeRolseDataSet(strUserID, intUserID);
                        this.pan6.Visible = true;
                        this.pan0.Visible = this.pan1.Visible = this.pan2.Visible = this.pan3.Visible = this.pan4.Visible = this.pan5.Visible = false;
                        break;
                }

                this.lblJs.Text = "<title>" + strTitle + "</title>";
            }
            else
            {
                this.lblJs.Text = "<script>window.close();</script>";
            }
        }
        else
        {
            this.lblJs.Text = "";
        }
    }

    protected void btnSumbit_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intItems = this.lstBox2.Items.Count - 1;
        string strMenuItems = "";

        for (int i = intItems; i >= 0; i--)
        {
            strMenuItems += this.lstBox2.Items[i].Value + "|";
        }

        Boolean is_Succeed = cls_Menu.MenuLicensedToRolse(intUserID, strMenuItems);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('系统菜单授权完毕！');</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('系统菜单授权失败，请重试！');</script>";
        }
    }

    protected void btnSubmit1_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();
        string strUserID = this.hidUserID.Value.Trim();
        string strMenuID = this.hidMenuID.Value.Trim();

        if (strUserID != "" && strMenuID != "")
        {
            int intUserID = Int32.Parse(strUserID);
            int intMenuID = Int32.Parse(strMenuID);

            //按钮授权
            int intItems = this.dgrd0.Items.Count - 1;
            string strButtonIDs = "";

            for (int i = intItems; i >= 0; i--)
            {
                bool is_checked = ((CheckBox)this.dgrd0.Items[i].FindControl("chkRsSelect")).Checked;

                if (is_checked)
                {
                    strButtonIDs += this.dgrd0.Items[i].Cells[1].Text.Trim() + "|";
                }
            }

            Boolean is_Succeed = cls_Menu.ButtonLicensedToRolse(intUserID, intMenuID, strButtonIDs);

            if (is_Succeed)
            {
                this.lblJs.Text = "<script>alert('该项菜单页按钮授权完毕！');</script>";
            }
            else
            {
                this.lblJs.Text = "<script>alert('该项菜单页按钮授权失败，请重试！');</script>";
            }

            //单据价格可见性授权
            int intVisible = (this.chkPriceVisible.Checked) ? 0 : 1;

            is_Succeed = cls_Menu.PriceVisibleLicensedToRolse(intUserID, intMenuID, intVisible);

            if (!is_Succeed)
            {
                this.lblJs.Text = "<script>alert('单据价格可见性设置失败，请重试！');</script>";
            }
        }
    }

    protected void btnSumbit2_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intItems = this.lstDept2.Items.Count - 1;
        string strDeptIDs = "";

        for (int i = intItems; i >= 0; i--)
        {
            strDeptIDs += this.lstDept2.Items[i].Value + "|";
        }

        Boolean is_Succeed = cls_Menu.DeptLicensedToRolse(intUserID, strDeptIDs);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('部门授权完毕！');</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('部门授权失败，请重试！');</script>";
        }
    }

    protected void btnSumbit3_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intItems = this.lstDepot2.Items.Count - 1;
        string strDepotIDs = "";

        for (int i = intItems; i >= 0; i--)
        {
            strDepotIDs += this.lstDepot2.Items[i].Value + "|";
        }

        Boolean is_Succeed = cls_Menu.DepotLicensedToRolse(intUserID, strDepotIDs);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('仓库授权完毕！');</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('仓库授权失败，请重试！');</script>";
        }
    }

    protected void btnSumbit4_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intItems = this.lstProductType2.Items.Count - 1;
        string strProductTypeIDs = "";

        for (int i = intItems; i >= 0; i--)
        {
            strProductTypeIDs += this.lstProductType2.Items[i].Value + "|";
        }

        Boolean is_Succeed = cls_Menu.ProductTypeLicensedToRolse(intUserID, strProductTypeIDs);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('商品类别授权完毕！');</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('商品类别授权失败，请重试！');</script>";
        }
    }

    protected void btnSubmit5_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intEdit1 = (this.chkBox1.Checked) ? 1 : 0;
        int intEdit2 = (this.chkBox2.Checked) ? 1 : 0;
        decimal pic1 = decimal.Parse(this.txt1.Text.Trim());
        decimal pic2 = decimal.Parse(this.txt2.Text.Trim());
        decimal pic3 = decimal.Parse(this.txt3.Text.Trim());
        decimal pic4 = decimal.Parse(this.txt4.Text.Trim());

        Boolean is_Succeed = cls_Menu.PriceLicensedToRolse(intUserID, intEdit1, pic1, pic2, intEdit2, pic3, pic4);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('价格授权设置完毕！');window.close();</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('价格授权设置失败，请重试！');</script>";
        }
    }

    protected void btnSumbit6_Click(object sender, EventArgs e)
    {
        ClsMenuDAL cls_Menu = new ClsMenuDAL();

        int intUserID = Int32.Parse(this.hidUserID.Value);
        int intItems = this.lstOderType2.Items.Count - 1;
        string strOderTypeIDs = "";

        for (int i = intItems; i >= 0; i--)
        {
            strOderTypeIDs += this.lstOderType2.Items[i].Value + "|";
        }

        Boolean is_Succeed = cls_Menu.OderTypeLicensedToRolse(intUserID, strOderTypeIDs);

        if (is_Succeed)
        {
            this.lblJs.Text = "<script>alert('客户类别授权完毕！');</script>";
        }
        else
        {
            this.lblJs.Text = "<script>alert('客户类别授权失败，请重试！');</script>";
        }
    }

    protected void chkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (this.chkBox1.Checked)
        {
            this.txt1.Enabled = this.txt2.Enabled = true ;
            this.lblJs.Text = "<script>document.getElementById('"+ this.txt1.ClientID +"').focus();</script>";
        }
        else
        {
            this.txt1.Enabled = this.txt2.Enabled = false;
        }
    }

    protected void chkBox2_CheckedChanged(object sender, EventArgs e)
    {
        if (this.chkBox2.Checked)
        {
            this.txt3.Enabled = this.txt4.Enabled = true;
            this.lblJs.Text = "<script>document.getElementById('" + this.txt3.ClientID + "').focus();</script>";
        }
        else
        {
            this.txt3.Enabled = this.txt4.Enabled = false;
        }
    }
}
